cmake_minimum_required(VERSION 3.3)
project(YOLO_TensorRT)


# We need c++14 for ROS2, thus just require it for everybody
# NOTE: To future self, hope this isn't an issue...
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
enable_language(CUDA)


# Enable compile optimizations
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -fsee -fomit-frame-pointer -fno-signed-zeros -fno-math-errno -funroll-loops")
## Enable debug flags (use if you want to debug in gdb)
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3 -Wall -Wuninitialized -Wmaybe-uninitialized -fno-omit-frame-pointer")


# Include libraries (if we don't have opencv 4, then fallback to opencv 3)
# The OpenCV version needs to match the one used by cv_bridge otherwise you will get a segmentation fault!
find_package(Eigen3 REQUIRED)
find_package(OpenCV 3 QUIET)
if (NOT OpenCV_FOUND)
    find_package(OpenCV 4 REQUIRED)
endif ()


##################################################
# Make the core library
##################################################
find_package(CUDA REQUIRED)

# need to set your own tensorRT directory
set(TensorRT_Dir "/usr/local/include/TensorRT-8.5.3.1")
set(TensorRT_LIB_Dir "${TensorRT_Dir}/targets/x86_64-linux-gnu/lib")
set(TensorRT_INCLUDE_Dir "${TensorRT_Dir}/include/")

include_directories(
        src
        ${EIGEN3_INCLUDE_DIR}

        src/deepNetwork/include
        ${CUDA_INCLUDE_DIRS}
        ${TensorRT_INCLUDE_Dir}
        ${TensorRT_Dir}/samples/common
)

add_library(tensorrt_libs
        # yolo
        src/deepNetwork/include/utils/kernel_function.cu
        src/deepNetwork/include/utils/utils.cpp
        src/deepNetwork/include/utils/yolo.cpp

        ${TensorRT_Dir}/samples/common/logger.cpp
        ${TensorRT_Dir}/samples/common/sampleOptions.cpp
        ${TensorRT_Dir}/samples/common/sampleUtils.cpp
)

target_link_libraries(tensorrt_libs
        ${OpenCV_LIBRARIES}
        ${CUDA_LIBRARIES}
        ${TensorRT_LIB_Dir}/libnvparsers.so
        ${TensorRT_LIB_Dir}/libnvinfer.so
        ${TensorRT_LIB_Dir}/libnvonnxparser.so
)



add_executable(app_yolov8_seg
        src/app_yolov8_seg.cpp
        src/deepNetwork/decode_yolov8_seg.cu
        src/deepNetwork/yolov8_seg.cpp
)
target_link_libraries(app_yolov8_seg tensorrt_libs)

add_executable(app_yolov8
        src/app_yolov8.cpp
        src/deepNetwork/decode_yolov8.cu
        src/deepNetwork/yolov8.cpp
)
target_link_libraries(app_yolov8 tensorrt_libs)


